package com.orangecy.infrastructure.persistent.repository;

import com.orangecy.infrastructure.persistent.DO.ItemDO;
import com.orangecy.infrastructure.persistent.DTO.ItemDTO;
import com.orangecy.infrastructure.persistent.common.AbstractDAO;
import com.orangecy.infrastructure.persistent.common.BaseMapper;
import com.orangecy.infrastructure.persistent.common.Convert;
import com.orangecy.infrastructure.persistent.mapper.CrudItemMapper;
import org.apache.ibatis.annotations.Mapper;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @Author : orangeCy.奕
 * @Product : 猎豹养成产品源码
 * @Time : 2021/10/29
 * @Desc :这里仓储层需要将数据模型DO转为传输模型表达给领域模型Model,采用DTO传输
 */
@Mapper
public class CurdItemDAO extends AbstractDAO<ItemDO> implements Convert<ItemDO, ItemDTO> {

    @Resource
    private CrudItemMapper crudItemMapper;

    @Override
    public BaseMapper<ItemDO> getMapper() {
        return crudItemMapper;
    }

    /**
     * 根据id获取商品信息
     * @param id
     * @return
     */
    public ItemDTO getItemById(Long id) {
        return convertDTO(crudItemMapper.findById(id));
    }

    @Override
    public ItemDTO convertDTO(ItemDO d) {
        ItemDTO itemDTO = new ItemDTO();
        itemDTO.setItemId(d.getItemId());
        itemDTO.setTitle(d.getTitle());
        itemDTO.setPrice(d.getPrice());
        //mock
        itemDTO.setSkuIds(new ArrayList<>());
        return itemDTO;
    }
}